package com.mljr.example.ui.sys;

import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;

import com.ctakit.sdk.app.base.BaseActivity;
import com.ctakit.sdk.app.utils.ViewUtil;
import com.ctakit.sdk.view.annotation.LayoutContentId;
import com.ctakit.sdk.view.annotation.ViewInject;
import com.mljr.example.R;


@LayoutContentId(R.layout.menu_call_dialog)
public class CallPhoneMenuPopupWindow extends BaseActivity implements OnClickListener {

	@ViewInject(R.id.phone)
	private TextView phoneView;
	@ViewInject(R.id.call)
	private Button call;
	@ViewInject(R.id.btn_cancel)
	private Button btn_cancel;


	public String phone;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		phone = getIntent().getStringExtra("phone");
		phoneView.setText(phone);
		btn_cancel.setOnClickListener(this);
		call.setOnClickListener(this);
	}
	@Override
	public boolean onKeyDown(int keyCode, KeyEvent event) {
		if (keyCode == KeyEvent.KEYCODE_BACK) {
			finish();
		}
		return false;
	}

	@Override
	public void finish() {
		super.finish();
		ViewUtil.bottomExitAnim(this);
	}

	// 实现onTouchEvent触屏函数但点击屏幕时销毁本Activity
	@Override
	public boolean onTouchEvent(MotionEvent event) {
		finish();
		return true;
	}

	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.call:
			callPhone();
			break;
		case R.id.btn_cancel:
			finish();
			break;
		default:
			break;
		}

	}

	private void callPhone() {
		Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse("tel:"+phone));
        startActivity(intent);
		finish();
	}

	 		 
	@Override
	public BaseActivity getActivity() {
		return CallPhoneMenuPopupWindow.this;
	}

	@Override
	public String getPageName() {
		return "CallPhoneMenuPopupWindow";
	}

}
